var base_url="http://"+location.host+"/";
$(".more").click(function(e){
    var url=location.href;
    var key=url.substring(url.indexOf("=")+1);
    var page=$(".book_list").attr("data_page");
    page=parseInt(page)+1
    var req_url=base_url+"api/search?key="+key+"&page="+page
    $.ajax({
        url:req_url,
        type:"GET",
        success:function(res){
            console.log(res);
            if(parseInt(res.cur_page)==res.total_page){
                $(".more").parent().text('<div class="weui-cell__bd nomore">没有数据了~_~</div>')
            }
            $(".book_list").attr("data_page",res.cur_page);
            res.data.forEach(function(v,i){
                html='<a href="/detail/'+v.book_id+'" class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__hd"><img class="weui-media-box__thumb" src="'+v.cover+'"></div><div class="weui-media-box__bd"><h4 class="weui-media-box__title"><h4>书名:&emsp;<em>'+v.book_name+'</em><em style="float:right">分类:&emsp;'+v.category_name_2+'</em></h4><h4>作者:&emsp;<em>'+v.author_name +'</em></h4></h4><p class="weui-media-box__desc">简介:'+v.intro+'</p></div></a>';
                $(".book_list").append(html);
            });
                    }
    });
});

$(".book").click(function(e){
    id=$(this).attr("data_id");
    document.cookie="img="+$(this).find("img").attr("src")+";path=/";
    document.cookie="intro="+$(this).find("p").text().replace(/[\s\n\t]+/g,'')+";path=/";
    location.href="/detail/"+id;
});
